import time

# # 装饰器不带参数
# def runTime(func):
#     print('装饰器开始运行！')
#     def wrapper(*args,**kwargs):
#         print('wrapper开始运行！')
#         start_time = time.time()
#         #执行原来函数的功能
#         func(*args,**kwargs)  # welcome_vip()
#         #执行扩展功能
#         time.sleep(1)
#         end_time = time.time()
#         const = end_time - start_time
#         print(f"统计{func.__name__}函数运行耗时{const}秒")
#     return wrapper
#
# @runTime	# 第一件事调用cal_time,第二件事把被装饰的函数名传给cal_time的形参fn
# def  welcome_vip():
#     print("欢迎来到VIP课堂")

# runTime(welcome_vip)()
# welcome_vip()


# 装饰器带参数:实质外面再包裹一个函数,最外层接收装饰器传入的参数，第二层接收传入被装饰的函数，第三层给被装饰函数传参进行逻辑判断
def demo(t):
    def runTime(func):
        def wrapper(*args, **kwargs):
            start_time = time.time()
            #执行原来函数的功能
            func(*args, **kwargs)
            #执行扩展功能
            time.sleep(t)
            end_time = time.time()
            const = end_time - start_time
            print(f"统计{func.__name__}函数运行耗时{const}秒")

        return wrapper
    return runTime

@demo(1)
def add_func(num1, num2):
    print("求和结果为：{}".format(num1+num2))

# test()

add_func(10, 20)